<template>
  <div>
    <el-row :gutter="10">
      <el-col :offset="16" :span="4">
        <el-select v-model="year" size="mini" @change="dateChange">
          <el-option v-for="item in selectYear" :key="item" :label="item" :value="item" />
        </el-select>
      </el-col>
      <el-col :span="3">
        <el-select v-model="month" size="mini" @change="dateChange">
          <el-option v-for="item in 12" :key="item" :label="item" :value="item" />
        </el-select>
      </el-col>
    </el-row>

    <el-calendar v-model="value">
      <template v-slot:dateCell="{date}">
        <div class="date-content">
          <span class="text">{{ date.getDate() }}</span>
          <span v-if="date.getDay() === 6 || date.getDay() === 0" class="rest">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  data() {
    return {
      year: '',
      month: '',
      selectYear: [],
      value: new Date()
    }
  },
  created() {
    const date = new Date()
    this.year = date.getFullYear()
    this.month = date.getMonth() + 1
    this.selectYear = Array(11)
      .fill(this.year)
      .map((item, index) => item - 5 + index)
  },
  methods: {
    dateChange() {
      this.value = new Date(this.year + '-' + this.month)
    }
  }
}
</script>

<style lang='less' scoped>
/deep/ .el-calendar__header {
  display: none;
}
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text {
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
}
/deep/ .el-calendar-table__row td,
/deep/ .el-calendar-table tr td:first-child,
/deep/ .el-calendar-table__row td.prev {
  border: none;
}
/deep/ .el-calendar-day {
  height: auto;
}
</style>
